<?php
/**
 * Created by PhpStorm.
 * User: 热心观众
 * Date: 2018/10/7
 * Time: 15:38
 */

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class DoLogin extends Controller
{
    public function DoLogin()
    {
        $data = input('post.');
        $name = input('name');
        $pass = input('pass');
          
        $result = Db::table('zz_user')->where('zz_name',$name)->where('zz_pass',$pass)->where('zz_status',1)->find();

        $res = [];
        if ($result) {
            Session::set('user',$data);
            $res['status'] = 1;
            return json($res);
        } else {
            $res['status'] = 0;
            return json($res);
        }
    }

    public function LoginOut()
    {
        $userSession = Session::get('user');
        // 判断有无Session
        if (empty($userSession)) {
            $msg = "您还没有登录！";
            $url = "../log/login";
            return $this->error($msg,$url);
        }
        //清空session
       // session('user',null);
        Session::delete('user');

        $res['status'] = 1;
        return json($res);

    }
}